home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Languguage OS 2
/
Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO
/
language
/
ici
/
ici.cpi
/
object.h
< prev
next >
Wrap
C/C++ Source or Header
|
1994-10-27
|
4KB
|
131 lines
#ifndef ICI_OBJECT_H
#define ICI_OBJECT_H
#ifndef ICI_FWD_H
#include "fwd.h"
#endif
/*
* Every object has a header, the o_type field of which is a pointer
* to its type...
*/
struct type
{
long (*t_mark)(); /* Mark an object of this type. */
void (*t_free)(); /* Free an object of this type. */
long (*t_hash)(); /* Return a hash of the object's value. */
int (*t_cmp)(); /* Object value compare (like types, eq => 0).*/
object_t *(*t_copy)(); /* Copy of object of this type. */
int (*t_assign)(); /* Assign to a sub element. */
object_t *(*t_fetch)(); /* Fetch a sub element. */
char *t_name; /* As used by typeof() & errors. */
};
#ifndef SMALL
/*
* Macros to perform the operation on the object.
*/
#define mark(o) ((objof(o)->o_flags & O_MARK) == 0 \
? (*(objof(o))->o_type->t_mark)(o) \
: 0L)
#define freeo(o) ((*(objof(o))->o_type->t_free)(o))
#define hash(o) ((*(objof(o))->o_type->t_hash)(o))
#define cmp(o1,o2) ((*(objof(o1))->o_type->t_cmp)((o1), (o2)))
#define copy(o) ((*(objof(o))->o_type->t_copy)(o))
#define fetch(o,k) ((*(objof(o))->o_type->t_fetch)((o), (k)))
#define assign(o,k,v) ((*(objof(o))->o_type->t_assign)((o), (k), (v)))
/*
* Link an object into the list of objects.
*/
#define rego(o) (objs_top < objs_limit \
? *objs_top++ = objof(o) \
: grow_objs(objof(o)))
#else
/*
* Functions to performs operations on the object.
*/
extern long mark();
extern void freeo();
extern long hash();
extern int cmp();
extern object_t *copy();
extern object_t *fetch();
extern int assign();
extern void rego();
#endif
/*
* References from ordinary machine data objects (ie. variables and stuff,
* not other objects) are invisible to the garbage collector. These refs
* must be accounted for if there is a possibility of garbage collection.
* Note that most routines that make objects (new_*(), copy() etc...)
* return objects with 1 ref. The caller is expected to loose() it when
* they attach it into wherever it is going.
*/
#ifndef BUGHUNT
#define got(o) (++objof(o)->o_nrefs)
#define loose(o) (--objof(o)->o_nrefs)
#endif
/*
* This is the universal header of all objects.
*/
struct object
{
char o_tcode; /* See TC_* below. */
char o_flags; /* See O_* below. */
char o_nrefs; /* No. of refs invisible to collect. */
char o_pad; /* Waiting for a use. */
type_t *o_type; /* See struct type above. */
/*
* Each object includes this as a header. In the real structures
* associated with each object type the type specific stuff follows...
*/
};
#define objof(x) ((object_t *)(x))
/*
* For static object initialisations...
*/
#define OBJ(tc,type) {(tc), 0, 1, 0, &type}
/*
* The upper nibble is considered available for type specific use.
*/
#define O_MARK 0x01 /* Garbage collection mark. */
#define O_ATOM 0x02 /* Is a member of the atom pool. */
/*
* The o_tcode field is a small int which allows bypassing the o_type
* pointer for some types. Any type not listed here will have a value
* of 0. The types listed will set a code here to allow some time
* critical areas of code to make quicker decisions (typically a switch)
* based on the type. It also allows faster decisions based on type
* combinations (see pair() below).
*/
#define TC_OTHER 0
#define TC_PC 1
#define TC_SRC 2
#define TC_PARSE 3
#define TC_OP 4
#define TC_STRING 5
#define TC_CATCH 6
#define TC_FORALL 7
#define TC_INT 8
#define TC_FLOAT 9
#define TC_REGEXP 10
#define TC_PTR 11
#define TC_ARRAY 12
#define TC_STRUCT 13
#define TC_SET 14
/* Max value of 15 dictated by PAIR (below). */
#define PAIR(a,b) (((a) << 4) + (b))
#define TRI(a,b,t) (((((a) << 4) + b) << 6) + t_subtype(t))
#ifndef ICI_NULL_H
#include "null.h"
#endif
#define isfalse(o) ((o) == objof(o_zero) || isnull(o))
#endif